# manual_tuning.py

import xgboost as xgb
from sklearn.metrics import accuracy_score

def manual_hyperparameter_tuning(X_train, y_train, X_val, y_val):
    # 定义几个手动选择的超参数组合
    manual_params = [
        {'learning_rate': 0.01, 'max_depth': 3, 'n_estimators': 50},
        {'learning_rate': 0.01, 'max_depth': 4, 'n_estimators': 75},
        {'learning_rate': 0.02, 'max_depth': 5, 'n_estimators': 100},
        {'learning_rate': 0.02, 'max_depth': 6, 'n_estimators': 125},
        {'learning_rate': 0.05, 'max_depth': 3, 'n_estimators': 100},
        {'learning_rate': 0.05, 'max_depth': 5, 'n_estimators': 150},
        {'learning_rate': 0.1, 'max_depth': 4, 'n_estimators': 75},
    ]

    manual_accuracies = []

    for idx, params in enumerate(manual_params):
        model = xgb.XGBClassifier(
            learning_rate=params['learning_rate'],
            max_depth=params['max_depth'],
            n_estimators=params['n_estimators'],
            objective='multi:softmax',
            num_class=10,
            eval_metric='mlogloss'
        )
        model.fit(X_train, y_train, eval_set=[(X_val, y_val)], verbose=False)
        y_pred = model.predict(X_val)
        accuracy = accuracy_score(y_val, y_pred)
        manual_accuracies.append(accuracy)
        print(f"Manual Tuning {idx+1}: Params={params}, Accuracy={accuracy:.4f}")

    return manual_accuracies, manual_params
